<?php

/**
 * Cookie
 * @author liuch
 * @version 1.0
 * @date 2017-07-27 17:45
 */
class Cookie {

    private $cookie;

    private $defaultCookie = array(
        "connect.sid" => "s%3Ar5f35z13mdRb9kxwEJWp_6pGZiQl-Kcm.GKEE8yQvwdiJ6cReQ%2B96%2Fsju5SKYdkM%2FJpnDnKUdnf8",
    );

    public function __construct() {
//        $cookie = json_decode(file_get_contents(ROOT_PATH . 'cookie.txt'), true);
//        $cookie || $cookie = array();
//        $this->cookie = array_merge($this->defaultCookie, $cookie);
        $this->cookie = $this->defaultCookie;
    }

    public function getCookie() {
        $cookieArr = array();
        foreach($this->cookie as $name => $value) {
            $cookieArr[] = "{$name}={$value}";
        }
        return implode('; ', $cookieArr);
    }

    public function saveCookie($cookie) {
        $cookie = array_merge($this->defaultCookie, $cookie);
        return file_put_contents(ROOT_PATH . 'cookie.txt', json_encode($cookie));
    }


}